home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / timeos2.zip / TIMESET.CMD next >
OS/2 REXX Batch file  |  1992-08-09  |  4KB  |  116 lines

  1. /* REXX */
  2. /* Procedure to call Naval Observatory and set System Time  */
  3. /* Author: Jerry am Ende, Compuserve 73237,131              */
  4. /* Date  : 08/09/92                                         */
  5. /*                                                          */
  6. /* Notes: Change Year to Current Year                       */
  7. /*        Change offset for Daylight Savings Time           */
  8. /*        This version is setup for COM2 change to COM1 if  */
  9. /*          needed                                          */
  10. /*                                                          */
  11.  
  12. parse arg year offset PhoneNumber ComPort
  13.  
  14. "CLS"                   /* Clear Screen */
  15.  
  16. if year = "" then do
  17.    say "Usage is: TIMESET <year> <offset> <PhoneNumber> <ComPort>"
  18.    say "          <year>        = 2 digit year (e.g. 1992 = 92)"
  19.    say "          <offset>      = Hours from Greenwich Mean time. Eastern"
  20.    say "                           Daylight Time = 4"
  21.    say "          <PhoneNumber> = Phone Number of Naval Observatory"
  22.    say "                           1-202-653-0351 is default"
  23.    say "          <ComPort>     = ComPort where modem is connected"
  24.    say "                           COM1 is default"
  25.    return
  26.    end
  27.  
  28. if offset == "" then                /* Set Defaults */
  29.    offset = 4
  30.  
  31. if PhoneNumber == "" then
  32.    PhoneNumber = "1-202-653-0351"
  33.  
  34. if ComPort == "" then
  35.    ComPort = "COM1"
  36.  
  37. modays.1 = 31           /* initialize days in each month */
  38. modays.2 = 28
  39. modays.3 = 31
  40. modays.4 = 30
  41. modays.5 = 31
  42. modays.6 = 30
  43. modays.7 = 31
  44. modays.8 = 31
  45. modays.9 = 30
  46. modays.10 = 31
  47. modays.11 = 30
  48. modays.12 = 31
  49.  
  50. if ((year // 4) == 0) then    /* Check for Leap Year */
  51.    modays.2 = 29
  52.  
  53. CrLf = X2C("0D0A")
  54.  
  55. State = STREAM(ComPort,"C","OPEN")
  56. "@MODE" ComPort":1200,E,7,1 > NUL"
  57.  
  58. CALL LINEOUT ComPort, "ATX3DT"PhoneNumber||CrLf    /* Dial In */
  59. StartTime = time('E')
  60. ReturnStuff = ""
  61. DO WHILE pos('UTC',ReturnStuff) == 0          /* UTC is end of String */
  62.   ReturnStuff = ReturnStuff||CHARIN(ComPort)
  63.   if (pos('BUSY',ReturnStuff) <> 0) then do   /* Check for Busy */
  64.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  65.      State = STREAM(ComPort,"C","CLOSE")
  66.      Say "Line Busy, Please Try Again..."
  67.      return
  68.      end
  69.   if ((time('E') - StartTime) > 45) then do   /* Check for Timeout */
  70.      CALL LINEOUT ComPort,"ATH"CrLf            /* Hang Up */
  71.      State = STREAM(ComPort,"C","CLOSE")
  72.      Say "Sorry, Timeout..."
  73.      return
  74.      end
  75. END
  76.  
  77. NavalString = Right(ReturnStuff,20)    /* Retrieve the time/date string */
  78.  
  79. CALL LINEOUT ComPort,"ATH"CrLf          /* Hang Up */
  80.  
  81. State = STREAM(ComPort,"C","CLOSE")
  82. parse var NavalString . doy time .
  83.  
  84. /* Convert time to HH:MM:SS */
  85. hour = right(left(time,2) - offset,2,'0')
  86. if (hour < 0) then do
  87.    hour = hour + 24
  88.    doy = doy - 1
  89.    end
  90. minute = right(substr(time,3,2),2,'0')
  91. second = right(substr(time,5,2),2,'0')
  92. TimeString = hour || ':' || minute || ':' || second
  93.  
  94. /* Convert doy to MM-DD-YY format */
  95. month = 0
  96. SumDays = 0
  97. do while (SumDays < doy)
  98.    month = month + 1
  99.    SumDays = SumDays + modays.month
  100. end
  101. SumDays = SumDays - modays.month
  102. Day = doy - Sumdays
  103. DateString = right(Month,2,'0') || '-' || right(Day,2,'0') || '-' || Year
  104.  
  105. OldTime = Time()
  106. OldDate = Date()
  107.  
  108. /* Send Date & Time to OS2 */
  109. "@DATE" DateString
  110. "@TIME" TimeString
  111.  
  112. Say "Date & Time was             " OldDate OLdTime
  113. Say "Date & Time has been Set to:" Date() Time()
  114.  
  115. return
  116.